package com.ebay.buyer;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.ebay.model.Book;
import com.ebay.services.Bidding;
import com.opensymphony.xwork2.ActionSupport;


public class ShowBookDetails extends ActionSupport{



	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getTimeLeft() {
		return timeLeft;
	}

	public void setTimeLeft(String timeLeft) {
		this.timeLeft = timeLeft;
	}

	public float getStartBid() {
		return startBid;
	}

	public void setStartBid(float startBid) {
		this.startBid = startBid;
	}

	public String getEndTime() {
		return new SimpleDateFormat("d MMMM yyyy, kk:mm:ss zz").format(endTime);
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public boolean isBiddingstatus() {
		return biddingstatus;
	}

	public void setBiddingstatus(boolean biddingstatus) {
		this.biddingstatus = biddingstatus;
	}

	public float getSubtotal() {
		return subtotal;
	}

	public void setSubtotal(float subtotal) {
		this.subtotal = subtotal;
	}

	public int getProduct_id() {
		return product_id;
	}

	public void setProduct_id(int product_id) {
		this.product_id = product_id;
	}

	public int getQuantitypurchased() {
		return quantitypurchased;
	}

	public void setQuantitypurchased(int quantitypurchased) {
		this.quantitypurchased = quantitypurchased;
	}

	public ArrayList<Book> getLstbooks() {
		return lstbooks;
	}

	public void setLstbooks(ArrayList<Book> lstbooks) {
		this.lstbooks = lstbooks;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int product_id;
	private String url;
	private ArrayList<Book> lstbooks = new ArrayList<Book>();
	private int quantitypurchased;
	private float subtotal;
	private Date endTime;
	private boolean biddingstatus = false;
	private float startBid;
	private String timeLeft;
	private String errorMsg;
	Book book;

	public String execute(){
		book = Book.getBookDetails(product_id);
		subtotal = book.getPrice()*quantitypurchased;
		//TODO:check timeleft
		if(book.getBiddingstatus()){
			Bidding bid = new Bidding(book.getCategory_id(),book.getSubcategory_id(),book.getProduct_id());
			bid.getBiddingDetails();
			System.out.println(bid.toString());
			biddingstatus = true;
			startBid = bid.getBidPrice();
			//timeLeft = bid.getTimeLeftString();
			endTime = bid.getEndTime();
			if(book.isExpired()){
				setErrorMsg("Sorry! The item you were trying to bid Expired!");
				return ERROR;
			}
			
		}else{
			//Buy Now
		}
		lstbooks.add(book);
		return SUCCESS;
	}
	
	

	

}